package com.example.demo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class Constent {

	public enum SEQUENCE {

		ITEM,
		/** 门店序列 */
		SHOP;
	}

	private static String domain;
	private static String fileUpUrl;
	private static String imgUrl;

	public static String getDomain() {
		return domain;
	}

	@Value("${web.domain}")
	public void setDomain(String domain) {
		Constent.domain = domain;
	}

	public static String getFileUpUrl(SEQUENCE sequence, Long id) {
		return String.format("%s/%s/%s.png", fileUpUrl.replace("file:", ""), sequence.name(), id);
	}

	@Value("${spring.resources.static-locations}")
	public void setFileUpUrl(String fileUpUrl) {
		Constent.fileUpUrl = fileUpUrl;
	}

	public static String getImgUrl(SEQUENCE sequence, Long id) {
		return domain + String.format("%s%s/%s.png", imgUrl.replace("**", ""), sequence.name(), id);
	}

	@Value("${spring.mvc.static-path-pattern}")
	public void setImgUrl(String imgUrl) {
		Constent.imgUrl = imgUrl;
	}

}
